// pages/testReport/testRrport.js
import mode from "../../utils/mode.js"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userMessage: {},
        reportId: '',
        moreStatus: false,
        fitStatus: false,
        avoidStatus: false,
        zheStatus: false,
        list: {},
        testData: "",
        dateStr: "",
        shareType: 1,
        shareData: { reportId: '', report_no: '', date: '', userName: '', proposal: '', fit: [], disable: [], num: '' },
        yijianList: [],     //自动加入购物车产品列表
        decText: '以下成分仅包含部分推荐使用的常用功效类成分， 并非指不包含的产品就不满足护肤需求。'
    },
    handleClickShare () {
        console.log('分享')
        var _this = this
        wx.navigateTo({
            url: '/pages/sharePoster/sharePoster',
            success: function (res) {
                res.eventChannel.emit('share', {
                    shareType: _this.data.shareType,
                    shareData: _this.data.shareData
                })
            }
        })
        this.triggerEvent('close', {
            pauseVideo: true
        })
    },
    lookMore () {
        this.setData({
            moreStatus: true
        })
    },
    shou () {
        this.setData({
            moreStatus: false
        })
    },
    fitShou () {
        this.setData({
            fitStatus: false
        })
    },
    fitMore () {
        this.setData({
            fitStatus: true
        })
    },
    avoidShou () {
        this.setData({
            avoidStatus: false
        })
    },
    avoidMore () {
        this.setData({
            avoidStatus: true
        })
    },
    showZhe (e) {
        let { index } = e.currentTarget.dataset
        let { decText } = this.data
        decText = index == 'one' ? '表内仅包含部分推荐的常用成分，不表示在未在此表内推荐的成分就不满足护肤需求。' : '表内仅包含部分需要避免的常用成分，不表示在未在此表内提示避免的成分就无需避免。'
        this.setData({
            zheStatus: true,
            decText
        })
    },
    closeZhe () {
        this.setData({
            zheStatus: false
        })
    },
    toCase () {
        wx.navigateTo({
            url: '/pages/scheme/scheme?id=' + this.data.list.id,
        })
    },
    toPro () {
        wx.navigateTo({
            url: '/pages/productRecom/productRecom?report_id=' + this.data.reportId + '&user_id=' + this.data.userMessage.id,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        let info = wx.getStorageSync('uinfo')
        that.setData({
            userMessage: info.user
        })
        that.getreportInfo(options, info)
        // that.getDate()
    },
    async getreportInfo (options, info) {  //获取报告详情
        let that = this
        wx.showLoading({
            title: '报告加载中'
        })
        //根据id查看报告详情
        if (options.id) {
            that.setData({
                reportId: options.id
            })
            await mode.getReportDetail(options.id).then(
                item => {
                    wx.hideLoading()
                    if (item.code == 1) {
                        that.data.list = item.data.report
                        let value = ""
                        item.data.report.proposal.forEach(item => {
                            value += item + '\n'
                        })
                        that.data.list.proposal = value.trim()
                        that.data.shareData.userName = info.user.user_nickname,
                            that.data.shareData.reportId = item.data.report.report_id,
                            that.data.shareData.report_no = item.data.report.report_no,             
                            that.data.shareData.userName = info.user.user_nickname,
                            that.data.shareData.effect = item.data.report.effect,
                            that.data.shareData.fit = item.data.report.main_text,
                            that.data.shareData.disable = item.data.report.disable,
                            that.data.shareData.num = item.data.report.num,
                            that.data.shareData.testOne = item.data.report.name,
                            that.data.shareData.testTwo = item.data.report.code,
                            that.data.shareData.testName = item.data.report.experience_product&&item.data.report.experience_product.goods_name?item.data.report.experience_product.goods_name:'',
                            that.data.shareData.testGoodUrl = item.data.report.experience_product&&item.data.report.experience_product.goods_thumb?item.data.report.experience_product.goods_thumb:'',
                        that.data.shareData.proposal = value.trim()
                        that.setData({
                            list: that.data.list,
                            testData: options.answer,
                            username: info.user.user_nickname,
                            dateStr: item.data.times.split(' ')[0].replace(/-/g, '.')
                        })
                        let num = that.data.list.name.substr(1)
                        let nameUrl = 'https://2am-project.cn/img/report_img/' + num + '.png'
                        that.data.shareData.imgUrl = that.data.list.experience_product.goods_thumb.replace(/http:\/\/2am-project.oss-cn-beijing.aliyuncs.com/, "https://2am-project.cn")
                        that.data.shareData.nameUrl = nameUrl,
                        that.data.shareData.date = that.data.dateStr,
                            that.setData({
                                'list.nameUrl': nameUrl
                            })
                    } else {
                        wx.showToast({
                            title: '加载失败',
                            icon: 'error'
                        })
                    }
                }
            )
        }
    },
    getDate () {
        var nowDate = new Date()
        var year = nowDate.getFullYear()
        var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) :
            nowDate.getMonth() + 1
        var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
            .getDate()
        var dateStr = year + "." + month + "." + day
        this.setData({
            dateStr: dateStr
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this
        var uinfo = wx.getStorageSync('uinfo')
        that.setData({
            userMessage: uinfo.user
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    }
})